<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        'use strict';

        // for (let j = 0; j < 6; j++) {
        //     if(strs[0][j] == strs[1][j] && strs[0][j] == strs[2][j]){
        //         str01 += strs[0][j];
        //     }
        // }
        // console.log(str01);


        var find = function (strs) {
            var str01 = "";
            var length = strs[0].length;
            for (let k = 1; k < strs.length; k++) {
                if (length > strs[k].length) {
                    length = strs[k].length;
                }

            }

            for (let i = 0; i < length; i++) {
                for (let j = 1; j < strs.length; j++) {
                    if (strs[i][j] != strs[0][j]) {
                        return str01;
                    }
                }
                str01 += strs[0][i];
            }
        }
        console.log(find("flower", "flow", "flight"));
    </script>

    <script>
        var longestCommonPrefix2 = function(strs) {
            var str01 = "";
            var length = strs[0].length;
            for (let k = 1; k < strs.length; k++) {
                if (length < strs[k].length) {
                    length = strs[k].length;
                }

            }

            for (let i = 0; i < length; i++) {
                for (let j = 1; j < strs.length; j++) {
                    if (strs[j][i] != strs[0][i]) return str01
                }
                str01 += strs[0][i];
            }
            return str01;
        };
        console.log(longestCommonPrefix2(["dog", "racecar", "car"]));
    </script>




    <script>
        var longestCommonPrefix = function(strs) {
            var re = '';
            for (var j = 0; j < strs[0].length; j++) { //第j位
                for (var i = 1; i < strs.length; i++) { //第i个
                    if (strs[i][j] != strs[0][j]) return re
                }
                re += strs[0][j];
            }
            return re;
        };
        console.log(longestCommonPrefix(["flower", "flow", "flight"]));
    </script>
</body>

</html>